//
//  LCBDAliPayViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/24.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCBDAliPayViewController.h"
#import "LCMineService.h"
#import "LCUserModel.h"

@interface LCBDAliPayViewController ()

@property (weak, nonatomic) IBOutlet UITextField *aliUserNameTfl;
@property (weak, nonatomic) IBOutlet UITextField *nameTfl;

@property (weak, nonatomic) IBOutlet UIButton *bindBtn;

@property (assign, nonatomic)BOOL isEdit;


@end

@implementation LCBDAliPayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.alipay.alipaychar.length) {
        self.isEdit = NO;
        self.aliUserNameTfl.text = self.alipay.alipaychar;
        self.nameTfl.text = self.alipay.alipayname;
        self.aliUserNameTfl.userInteractionEnabled = NO;
        self.nameTfl.userInteractionEnabled = NO;
        [self.bindBtn setTitle:@"修改" forState:UIControlStateNormal];
    } else {
        self.isEdit = YES;
        self.aliUserNameTfl.text = @"";
        self.nameTfl.text = @"";
        self.aliUserNameTfl.userInteractionEnabled = YES;
        self.nameTfl.userInteractionEnabled = YES;
        [self.bindBtn setTitle:@"绑定" forState:UIControlStateNormal];
    }
}

- (IBAction)bingBtnAction:(UIButton *)sender {
    [self.view endEditing:YES];
    if (self.isEdit) {
        if (self.aliUserNameTfl.text.length <= 0) {
            [self showErrorText:self.aliUserNameTfl.placeholder];
        } else if (self.nameTfl.text.length <= 0) {
            [self showErrorText:self.nameTfl.placeholder];
        } else {
            [self bingAlipay];
        }
    } else {
        self.isEdit = YES;
        self.aliUserNameTfl.text = @"";
        self.nameTfl.text = @"";
        self.aliUserNameTfl.userInteractionEnabled = YES;
        self.nameTfl.userInteractionEnabled = YES;
        [self.bindBtn setTitle:@"绑定" forState:UIControlStateNormal];
    }
}

-(void)bingAlipay {
    [LCMineService bingAlipayInfoWithChar:self.aliUserNameTfl.text Name:self.nameTfl.text Block:^(BOOL isSuccess) {
        if (isSuccess) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
